<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="">
    <meta name="author" content="ThemeBucket">
    <link rel="shortcut icon" href="#" type="image/png">

    <title>学生用户登录</title>

    <link href="css/style.css" rel="stylesheet">
    <link href="css/style-responsive.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
    <script src="js/html5shiv.js"></script>
    <script src="js/respond.min.js"></script>
    <![endif]-->
</head>

<body class="login-body">

<div class="container"  >
    <br><br><br>

            <form class="form-signin" action="" id="userloginform">
                <div class="form-signin-heading text-center">
                    <img src="images/sylogo.jpg" height="150" width="150"/>
                </div>
                <div class="login-wrap">
                    <input type="text" class="form-control" placeholder="账号" autofocus name="u_acount" id="u_acount"
                           autocomplete="off">
                    <input type="password" class="form-control" placeholder="密码" name="u_password" id="u_password"
                           oncopy="return false" onpaste="return false" oncut="return false" oncontextmenu="return false">
                    <input type="text" class="form-control" placeholder="输入验证码或者回答问题" name="u_checkcode" id="u_checkcode"
                           autocomplete="off">
                    <div>
                        <div class="checkcode" style="height: 50px;" onclick="updatecheckCode()" id="checkcode">
                            <div style="width: 50%;float: left">
                                <img id="codeImg" src="producer/selfdefinitionkaptcha">
                            </div>

                            <div style="width: 50%;float: left">
                                <button class="btn " type="button">
                                    点击刷新验证码
                                </button>
                            </div>
                        </div>
                        <button class="btn btn-lg btn-login btn-block" type="button" onclick="userlogin()" id="userlogin">
                            <i class="fa fa-check"></i>
                        </button>
                    </div>
                    <div class="registration">&nbsp;&nbsp;
                        &nbsp;&nbsp;
                        <span>没有账户?
                    <a class="" onclick="insertuser()">
                        注册
                    </a>
                </span>
                    </div>
                    <label class="checkbox">
                        <input type="checkbox" value="remember-me"> 记住信息
                        <span class="pull-right">
                    <a data-toggle="modal" href="#myModal"> 忘记密码?</a>

                </span>
                    </label>

                </div>

                <!-- Modal -->
                <div aria-hidden="true" aria-labelledby="myModalLabel" role="dialog" tabindex="-1" id="myModal"
                     class="modal fade">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                <h4 class="modal-title">忘记密码?</h4>
                            </div>
                            <div class="modal-body">
                                <p>在下方输入你的电子邮件地址以重设密码。</p>
                                <input type="text" name="email" placeholder="Email" autocomplete="off"
                                       class="form-control placeholder-no-fix">

                            </div>
                            <div class="modal-footer">
                                <button data-dismiss="modal" class="btn btn-default" type="button">取消</button>
                                <button class="btn btn-primary" type="button">提交</button>
                            </div>
                        </div>
                    </div>
                </div>
                <!-- modal -->

            </form>

    <div style=";text-align: center;color: #8cc657;margin-top: 30px">

    </div>

</div>


<!-- Placed js at the end of the document so the pages load faster -->

<!-- Placed js at the end of the document so the pages load faster -->
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/modernizr.min.js"></script>
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<script type="text/javascript">


    $("#userlogin").click(function () {
        userlogin();
    });

    $(document).keydown(function () {
        if (event.keyCode == 13) {//回车键的键值为13
            userlogin();
        }
    });

    function updatecheckCode() {
        // window.location.reload();
        // parent.location.reload();

        $(".checkcode").load(location.href+" .checkcode");
    }

    function userlogin() {
        var u_acount = document.getElementById("u_acount").value;
        if (u_acount == null || u_acount == '') {
            swal("账号不能为空!", "请输入账号进行登录", "error");
            return false;
        }
        var u_password = document.getElementById("u_password").value;
        if (u_password == null || u_password == '') {
            swal("密码不能为空!", "请输入密码进行登录", "error");
            return false;
        }
        var data = $('#userloginform').serialize();//表单序列化 form表单的id属性值
        $.ajax({
            url: "/user/login_to",//url 统一资源定位符
            type: "POST",
            data: data,
            success: function (result) {

                if (result == 'error') {
                    swal("登录失败!", "账号或密码出现错误", "error");
                } else if (result.search('同学') != -1) {
                    swal("登录成功!", "请稍后......", "success");
                    window.sessionStorage.setItem("stu_u_name", result);
                    window.location.href = "showCompInfoIndex";
                } else if (result.search('账号禁用') != -1) {
                    swal("登录失败!", "账号已被禁用,请联系管理员", "error");
                    return false;
                } else if (result.search('验证码错误') != -1) {
                    swal("验证码错误", "请输入正确的验证码进行登录", "error");
                    return false;
                } else {
                    swal("身份错误", "该登录用户不是学生用户", "error");
                    return false;
                }
            },
            error: function (data) {

            }
        });
    }

    function insertuser() {
        window.location.href = "registration";
    }

    function loginTel() {
        window.location.href = "loginTel";
    }

    $(document).ready(function () {
        $('#checkcode').click(function () {
            $.ajax({
                url: 'image/getCheckCode',
                type: 'get',
                success: function (data, status, xhr) {
                    $('#checkcode').attr('src', 'getCheckCode');
                },
            });
        });
    });

</script>

</body>
</html>
